package com.tanhua.recommend.listener;

import com.alibaba.fastjson.JSON;
import com.tanhua.commons.templates.TencentCloudTemplate;
import com.tanhua.dubbo.api.mongo.SoundApi;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;


@Component
@RocketMQMessageListener(topic = "tanhua-sound",consumerGroup = "tanhua-sound-consumer")
@Slf4j
public class SoundMessageListener implements RocketMQListener<String> {

    @Autowired
    private TencentCloudTemplate tencentCloudTemplate;

    @Reference
    private SoundApi soundApi;

    @Override
    public void onMessage(String msg) {
        Map map = JSON.parseObject(msg, Map.class);
        String id = map.get("id").toString();
        String soundUrl = map.get("soundUrl").toString();

        //将soundUrl送检
        String taskId = tencentCloudTemplate.soundSend(soundUrl);

        soundApi.update(id,taskId);
    }
}
